package com.jumi.microservice.order.pipeline;

import com.jumi.microservice.common.exception.BaseException;
import com.jumi.microservice.order.context.TransHandlerContext;
import com.jumi.microservice.order.handler.TransHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Dirk
 * @Date 2020-08-04 17:34
 */
public class TransHandlerNode {

    private static final Logger log = LoggerFactory.getLogger(TransHandlerNode.class);

    private TransHandler handler;

    private TransHandlerNode next = null;

    public void exec(TransHandlerContext context) {
        boolean result = this.handler.handler(context);
        if (!result) {
            throw new BaseException(500, "创建订单失败");
        }
        if (next != null) {
            next.exec(context);
        }
    }

    public TransHandler getHandler() {
        return handler;
    }

    public void setHandler(TransHandler handler) {
        this.handler = handler;
    }

    public TransHandlerNode getNext() {
        return next;
    }

    public void setNext(TransHandlerNode next) {
        this.next = next;
    }
}

